package net.atomarrow.bs.controller;

import com.alibaba.fastjson.JSON;
import net.atomarrow.action.UrlParamIndex;
import net.atomarrow.bs.domain.TbPerson;
import net.atomarrow.bs.domain.TbStudent_T;
import net.atomarrow.render.Render;
import net.atomarrow.sy.base.BaseController;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class HelloController extends BaseController{


	public Render getOne(@UrlParamIndex(0) Integer id, String name, Boolean enable,
	                     Date date) {
		System.out.println(id);
		System.out.println(name);
		System.out.println(enable);
		System.out.println(date);
		return renderJsonSuccess();
	}

	public Render ajaxOne(@UrlParamIndex(0)Integer id, String name, Date date,
	                      Integer[] classIds,
	                      Integer age,
	                      TbPerson person,
	                      List<TbPerson> personList,
	                      TbPerson[] persons,
	                      Map<String, TbPerson> map) {
		System.out.println("id:" + id);
		System.out.println("classIds:" + JSON.toJSONString(classIds));
		System.out.println("name: " + name);
		System.out.println("date:" + date);
		System.out.println("age:" + age);
		System.out.println("person:" + JSON.toJSONString(person));
		System.out.println("personList: " + JSON.toJSONString(personList));
		System.out.println("persons:" + JSON.toJSONString(persons));
		System.out.println("map:" + JSON.toJSONString(map));
		System.out.println("getParamclassIds: " + getParamIntArray("classIds")[0]);
		return renderJsonData(name);
	}

	public Render ajaxTwo(@UrlParamIndex(0)Integer id, String name, Date date,
	                      Integer age,
	                      TbPerson person,
	                      List<TbPerson> personList
	                      ) {
		System.out.println("id:" + id);
		System.out.println("name: " + name + "---- getParamName:" + getParamString("name"));

		System.out.println("date:" + date);
		System.out.println("age:" + age);
		System.out.println("person:" + JSON.toJSONString(person));
		System.out.println("personList: " + JSON.toJSONString(personList));
		System.out.println("getParamPersons: " + getParamList("personList", TbPerson.class).get(0).getName());
		return renderJsonSuccess();
	}


//
//    private HelloService helloService;
//    
////    @HttpMethod(Method.GET)
//    public Render hi(){
//        System.out.println(getParamString("hello"));
//        System.out.println(getAttr("hello"));
//        System.out.println("hi controller");
//        helloService.sayHello();
//        setAttr("users",helloService.getAll());
//        setAttr("users2",helloService.addAll2());
//        return renderJsp("/hello/hi");
//    }
//    
//    public Render form(){
//    	return renderJsp("/hello/form");
//    }
//    
//    public Render addlist(){
//    	UploadFile file=getFile("img");
//    	System.out.println(file.getSaveDirectory());
//    	TbUser user=getParamObject("user", TbUser.class);
//    	List<TbUser> users=getParamList("users", TbUser.class);
//    	System.out.println(users);
////    	setAttr("img","http://"+ServerUtil.getIp(getRequest())+"/Atomarrow/upload/"+file.getFileName());
//    	return renderJsp("/hello/form");
//    }
//    public Render execute(){
//        return renderJsp("/hello/form");
//    }
//    
//    public String getHello(){
//        return null;
//    }
//    
//    @UnCheck
//    public Render test1(){
//        return renderJsonSuccess("hello");
//    }
//    
//    public Render test2(){
//        return renderJsonData(new Pager());
//    }
//    
	
	public Render testRedirect1(){
		return renderJspRedirect("abc");
	}
	public Render testRedirect2(){
		return renderJspRedirect("/abc");
	}
	public Render testRedirectAction1(){
		setAttr("hello", "hello");
		return renderAction("/hello/method1");
	}
	public Render testRedirectAction2(){
		setAttr("hello", "hello");
		return renderActionRedirect("method1");
	}
	public Render testRedirectAction3(){
		setAttr("hello", "hello");
		return renderActionRedirect("/hello/method1");
	}
	public Render method1(){
		System.out.println(getAttr("hello"));
		TbStudent_T student = getParamObject("student",TbStudent_T.class);
		System.out.println(student.getName());
		return renderJsonSuccess();
	}
	public Render intArray(){
		Integer[] ids = getParamIntArray("ids");
		if(ids!=null){
			
			for(int id:ids){
				System.out.println(id);
			}
		}
		return renderJsonSuccess();
	}
}
